package com.huanzhidadi.rabbitmq.seqqueuewithredis.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class SeqQueueConfig {

    /**
     * 创建队列，处理顺序消息
     * @return
     */
    @Bean
    public Queue seqQueue() {
        return createQueue("q_seq");
    }

    /**
     * 创建一个单活模式的队列
     * @param name
     * @return
     */
    private Queue createQueue(String name) {
        // return new Queue(name, true, false, false);
        return new Queue(name);
    }

    /**
     * 交换机
     * @return
     */
    @Bean
    public FanoutExchange seqFanoutExchange() {
        return new FanoutExchange("fanout_seq");
    }

    @Bean
    Binding bindingExchangeFanout(Queue seqQueue, FanoutExchange seqFanoutExchange) {
        return BindingBuilder.bind(seqQueue).to(seqFanoutExchange);
    }

}
